package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.dataDictionary.*;
import com.boatAnchorAssistant.pojo.vo.dataDictionary.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 * web/数据字典
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/dataDictionary/web")
public class DataDictionaryWebController {

    private final DataDictionaryService service;

    public DataDictionaryWebController(DataDictionaryService service) {
        this.service = service;
    }


    /**
     * 创建数据字典
     *
     * @param param
     * @return
     */
    @PostMapping("/createDataDictionary")
    public ApiResult createDataDictionary(@RequestBody @Valid CreateDataDictionaryParam param) {
        service.createDataDictionary(param);
        return ApiResult.ok();
    }


    /**
     * 修改数据字典
     *
     * @param param
     */
    @PutMapping("/editDataDictionary")
    public ApiResult editDataDictionary(@RequestBody @Valid EditDataDictionaryParam param) {
        service.editDataDictionary(param);
        return ApiResult.ok();
    }

    /**
     * 移除数据字典
     *
     * @param id
     */
    @DeleteMapping("/removeDataDictionary")
    public ApiResult removeDataDictionary(@RequestParam("id") Long id) {
        service.removeDataDictionary(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用数据字典
     *
     * @param id
     */
    @GetMapping("/enabledDataDictionary")
    public ApiResult enabledDataDictionary(@RequestParam("id") Long id) {
        service.enabledDataDictionary(id);
        return ApiResult.ok();
    }

    /**
     * 获取数据字典详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getDataDictionary")
    public ApiResult<GetDataDictionaryVo> getDataDictionary(@RequestParam("id") Long id) {
        GetDataDictionaryVo vo = service.getDataDictionary(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取数据字典列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getDataDictionaryList")
    public ApiResult<PageResult<GetDataDictionaryListVo>> getDataDictionaryList(@RequestBody GetDataDictionaryListParam param) {
        PageResult<GetDataDictionaryListVo> result = service.getDataDictionaryList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取数据字典下拉列表
     *
     * @return
     */
    @PostMapping("/getDataDictionaryDownList")
    public ApiResult<List<GetDataDictionaryDownListVo>> getDataDictionaryDownList(@RequestBody(required = false) @Valid GetDataDictionaryDownListParam param) {
        List<GetDataDictionaryDownListVo> list = service.getDataDictionaryDownList(param);
        return ApiResult.ok(list);
    }


}

